{% extends "layui/admin/base.html" %}
{% block title %}访问日志{% endblock %}


{% block content %}
    <blockquote class="layui-elem-quote">
        <p><a href="/admin/v2"><i class="layui-icon layui-icon-home"></i> 首页</a>
            <i class="layui-icon layui-icon-next"></i> 日志查看</p>
    </blockquote>
    <div class="layui-panel">
        <br>
        <div class="layui-card">
            <div class="layui-card-header">
                <h1>日志查看</h1>
            </div>
            <div class="layui-card-body">
                <table id="logTable" lay-filter="logTableFilter"></table>
            </div>
        </div>
        <br>
    </div>
{% endblock %}

{% block scripts %}
    <script>
        layui.use(['table', 'form', 'layer'], function () {
            const table = layui.table;
            const layer = layui.layer;
            const $ = layui.$;
            table.render({
                elem: '#logTable',
                url: '/api/logs/',
                method: 'get',
                headers: {
                    'Authorization': 'Bearer ' + localStorage.getItem('token')
                },
                page: true,
                parseData: function (res) {
                    return {
                        code: res.code,
                        msg: res.msg,
                        count: res.count,
                        data: res.data
                    }
                },
                cols: [[
                    {field: 'id', title: 'ID', width: 60, sort: true},
                    {field: 'ip', title: 'IP 地址', width: 150},
                    {field: 'country', title: '国家', width: 200},
                    {field: 'province', title: '省份', width: 200},
                    {field: 'city', title: '城市', width: 200},
                    {field: 'path', title: '访问页面', width: 200},
                    {field: 'created_at', title: '访问时间', width: 200},
                    {field: 'is_outside', title: '是否外网', width: 120}
                ]],
                text: {
                    none: '暂无日志数据'
                }
            })
        });
    </script>
{% endblock %}
